package org.example.business_logic.action;

import javafx.util.Pair;
import org.example.physics_engine.collision.CollisionFilter;
import org.example.physics_engine.collision.detector.BasicCollisionDetector;
import org.example.physics_engine.collision.manifold.Manifold;
import org.example.physics_engine.body.PhysicsBody;
import org.example.physics_engine.geometry.Vector2d;

import java.util.ArrayList;
import java.util.List;

public class OrbitAction implements UpdateListener {
    private final List<PhysicsBody> balls;

    private final List<PhysicsBody> orbits;

    private final List<CollisionFilter> filters;

    private final BasicCollisionDetector collisionDetector = new BasicCollisionDetector();

    public OrbitAction(List<PhysicsBody> balls, List<PhysicsBody> orbits, Vector2d gravity) {
        this.balls = balls;
        this.orbits = orbits;
        this.filters = new ArrayList<>();
        filters.add(new StraightOrbitAction(gravity));
        filters.add(new CurvedOrbitAction(gravity));
    }

    public List<Pair<Manifold, Pair<PhysicsBody, PhysicsBody>>> tick() {
        return collisionDetector.detect(balls, orbits, filters);
    }
}
